<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="股指期货">
        <el-input
            v-model="queryParams.instrument"
            placeholder="请输入股指期货"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            size="small"
            @click="handleExport"
            v-hasPermi="['marketdata:equity:equityFuture:equityFutureInfo:export']"
        >当页导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            size="small"
            @click="handleExportAll"
            v-hasPermi="['marketdata:equity:equityFuture:equityFutureInfo:export']"
        >全量导出
        </el-button>
      </el-col>
    </el-row>

    <xTable ref="equityFutureRef" refId="equityFutureRef" multiple="false" v-loading="loading" :data="equityFuturesList">
      <template #columList>
        <el-table-column label="序号" type="index" width="60"/>
        <el-table-column label="合约代码" align="center" prop="iCode" />
        <el-table-column label="合约名称" align="left" prop="siName" />
        <el-table-column label="产品类型" align="center" prop="aType" >
          <template #default="scope">
            <dict-tag :options="A_TYPE" :value="scope.row.aType" />
          </template>
        </el-table-column>
        <el-table-column label="上市日期" align="center" prop="listDate" />
        <el-table-column label="合约乘数" align="right" prop="lotsize" :formatter="formartTableP4"/>
        <el-table-column label="结算方式" align="center" prop="settlementType" >
          <template #default="scope">
            <span>{{ scope.row.settlementType == P ? "实物" : "现金" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="配对缴款日" align="center" prop="maturityDate" />
        <el-table-column label="最后交易日" align="center" prop="lastTradeDate" />
        <el-table-column label="保证金率" align="right" prop="marginRate" :formatter="formartTableP4" />
      </template>
    </xTable>
    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>


<script setup name="EquityFuturesInfo">
import {getEquityFuturesInfoList} from '@/api/marketdata/equity/equityFutures';

const {proxy} = getCurrentInstance();
const {M_TYPE, A_TYPE, CURRENCY} = proxy.useDict("M_TYPE", "A_TYPE", "CURRENCY");
import xTable from "@/xquant/base/xTable";
const equityFuturesList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([]);

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 20,
    instrument: undefined
  }
});

const {queryParams} = toRefs(data);

/** 查询列表 */
function getList() {
  loading.value = true;
  getEquityFuturesInfoList(queryParams.value).then(response => {
    equityFuturesList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}


/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}


/** 导出按钮操作 */
function handleExport() {
  proxy.download("marketdata/futuresController/export", {
    ...queryParams.value
  }, `股指期货信息${new Date().getTime()}.xlsx`);
}

/** 导出按钮操作 */
function handleExportAll() {
  proxy.download("marketdata/futuresController/export", Object.assign({
    ...queryParams.value
  }, {pageSize: ''}), `股指期货信息${new Date().getTime()}.xlsx`);
}


/** 重置按钮操作 */
function resetQuery() {
  queryParams.value.instrument = null;
  queryParams.value.pageNum = 1;
  getList();
}

getList();
</script>
